﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeTalk
{
    public class OutputHandler
    {
        public OutputHandler()
        {

        }

        /// <summary>
        /// Deletes the last character in document if it matches the given character. 
        /// </summary>
        /// <param name="c">The character to match. </param>
        public void RemoveLastChar(char c)
        {
            SendKeys("+{LEFT}^c");
            string s = InputHandler.ReadSelectedText();
            if (s != null && s.Length == 1)
            {
                if (c == s[0])
                    SendKeys("{BKSP}");
                else
                    SendKeys("{RIGHT}");
            }
        }

        public void SendKeys(string s)
        {
            // TODO: Don't send keys if this program has focus. 
            System.Windows.Forms.SendKeys.SendWait(s);
        }
    }
}
